// upPassword.js
var app=getApp()
import { showTi, showToast} from "../../utils/modal.js"
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    user:{},    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      user: wx.getStorageSync('wechat_user')
    })
    console.log(this.data.user)
  },
  bindHandlerChange:function(e){
    let type = e.currentTarget.dataset.type;
    let obj = {};
    obj[type] = e.detail.value;
    this.setData(obj);
  },
  changePass:function(){
    if (!this.data.old_password){
      showTi("请填写原密码")
    } else if (!this.data.new_password){
      showTi("请填写新密码")
    } else if (!this.data.confirmpassword) {
      showTi("请填写确认密码")
    } else if (this.data.confirmpassword != this.data.new_password){
      showTi("两次密码输入不一致")
    }else{
      delete this.data.user
      console.log(this.data)
      app.query("web/change_password", this.data, 'post').then(res => {
        if (res.code === 200) {
          console.log(res)
          showToast("修改成功")
          wx.redirectTo({
            url: '../login/login',
          })
        }else{
          showTi(res.msg)
        }
      })
    }  
  }
})